package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.hotel.domain.Hotel;
import cn.wolfcode.luowowo.hotel.domain.HotelCity;
import cn.wolfcode.luowowo.hotel.query.HotelQuery;
import cn.wolfcode.luowowo.hotel.service.IHotelCityService;
import cn.wolfcode.luowowo.hotel.service.IHotelDestService;
import cn.wolfcode.luowowo.hotel.service.IHotelService;
import cn.wolfcode.luowowo.hotel.service.IHotelTagService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("hotel")
public class HotelController {
    @Reference
    private IHotelTagService hotelTagService;//标签

    @Reference
    private IHotelService hotelService;//酒店

    @Reference
    private IHotelCityService hotelCityService;//城市

    @Reference
    private IHotelDestService hotelDestService;//区域

    /**
     * 酒店首页
     *
     * @return
     */
    @RequestMapping("")
    public String hotel(Model model) {
        //查询国内城市
        model.addAttribute("dest", hotelCityService.getDest());
        //查询国外城市
        model.addAttribute("overseas", hotelCityService.getForeignCity());
        //查询主题标签
        model.addAttribute("hotelTags", hotelTagService.getTheme());
        //查询城市标签
        model.addAttribute("hotelCity", hotelCityService.getCity());
        return "hotel/hotel";
    }

    /**
     * 通过主题查询推荐城市
     *
     * @return
     */
    @RequestMapping("theme")
    public String theme(Model model, HotelQuery qo) {
        List<HotelCity> list = hotelCityService.getHotelByTheme(qo.getContent());
        model.addAttribute("list", list);
        return "hotel/hotelTpl";
    }

    /**
     * 通过城市查询推荐酒店
     *
     * @return
     */
    @RequestMapping("theme1")
    public String theme1(Model model, HotelQuery qo) {
        List<Hotel> hotelScore = hotelService.getHotelByCity(qo.getName());
        model.addAttribute("hotelScore", hotelScore);
        return "hotel/hotelTpl1";
    }

    /**
     * 酒店搜索
     *
     * @return
     */
    @RequestMapping("h")
    public String h(Model model, @ModelAttribute("qo") HotelQuery qo) {
        List<Hotel> list = hotelService.query(qo);
        model.addAttribute("hotel", list);
        model.addAttribute("dest", hotelDestService.selectAll());
        return "hotel/jiudian";
    }

    /**
     * 点击主题查询城市下的酒店
     *
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("h/{name}")
    public String h1(Model model, @ModelAttribute("qo") HotelQuery qo) {
        List<Hotel> list = hotelService.query(qo);
        model.addAttribute("hotel", list);
        model.addAttribute("dest", hotelDestService.selectAll());
        return "hotel/jiudian";
    }


}
